package com.leap.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.leap.entity.Account;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

@Mapper
public interface AccountMapper extends BaseMapper<Account> {

    @Select("SELECT 1 FROM interact WHERE account_id = #{accountId} AND article_id = #{articleId}")
    String isLikeByArticleId(Long articleId, Long accountId);

    @Select("SELECT 1 FROM interact_comment WHERE account_id = #{accountId} AND comment_id = #{commentId}")
    String isLikeByCommentId(Long commentId, Long accountId);

    @Insert("INSERT INTO interact(article_id, account_id,create_time) VALUES (#{articleId} , #{accountId}, #{createTime});")
    int insertLike(Long articleId, Long accountId, LocalDateTime createTime);

    @Insert("INSERT INTO interact_comment ( account_id, comment_id, create_time) VALUES ( #{accountId}, #{commentId}, #{createTime});")
    int insertCommentLike(Long commentId, Long accountId, LocalDateTime createTime);

    @Delete(("DELETE FROM interact WHERE article_id = #{articleId} AND account_id = #{accountId}"))
    int deleteLike(Long articleId, Long accountId);

    @Delete(("DELETE FROM interact_comment WHERE comment_id = #{commentId} AND account_id = #{accountId}"))
    int deleteCommentLike(Long commentId, Long accountId);

}
